package com.lson.dynamic;

import com.lson.utils.SpringContext;
import org.springframework.context.ApplicationContext;
import org.springframework.util.ReflectionUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

@RequestMapping("dynamic")
@RestController
public class DynamicController {
    @RequestMapping("/insert")
    public String insert(String url,String controller,String method) throws Exception {
        ApplicationContext context = SpringContext.getApplicationContext();
        RequestMappingHandlerMapping requestMappingHandlerMapping= context.getBean(RequestMappingHandlerMapping.class);
        Method mappingForMethod =ReflectionUtils.findMethod(RequestMappingHandlerMapping.class, "getMappingForMethod",Method.class,Class.class);
        mappingForMethod.setAccessible(true);
        RequestMappingInfo mapping_info = (RequestMappingInfo) mappingForMethod.invoke(requestMappingHandlerMapping);


        return "success";
    }
}
